/*
 * @Author: lixiang
 * @Date: 2021-10-22 17:20:53
 * @Description: 
 */
/*
 * @Author: lixiang
 * @Date: 2020-06-11 10:58:07
 * @Description: 弹框封装
 */
import { MessageBox } from 'element-ui';

/**
 * @description: 询问弹框
 * @param {type}
 * @return:
 */

export function model(
  content,
  confirmButtonText,
  showCancelButton = true,
  cancelButtonText = "取消",
  title = "提示",
) {
  return new Promise((resolve, reject) => {
    MessageBox.confirm(content, title, {
      confirmButtonText: '确定',
      cancelButtonText,
      type: 'warning'
    }).then((res) => {
      resolve(res);
    
    }).catch((err) => {
      reject(err);
           
    });
  })
    
}

/**
 * @description: 输入弹框
 * @param {type}
 * @return:
 */

export function prompt(
  content,
  confirmButtonText,
  showCancelButton = true,
  cancelButtonText = "取消",
  title = "提示",
  inputPattern,
  inputErrorMessage
) {
  return new Promise((resolve, reject) => {
    MessageBox.prompt(content, title, {
          confirmButtonText,
      cancelButtonText,
          inputPattern,
          inputErrorMessage
        }).then(({ value }) => {
          resolve(value)
        }).catch((err) => {
          reject(err)       
        });
  })   
}

function beforeClose(action, done) {
  if (action === "confirm") {
    setTimeout(done, 1000);
  } else {
    done();
  }
}

